"log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"miow 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
+ "openssl 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 0.1.58 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)",
"semver 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
+[[package]]
+name = "bitflags"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
[[package]]
name = "bufstream"
version = "0.1.1"
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
+[[package]]
+name = "lazy_static"
+version = "0.1.16"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
[[package]]
name = "lazy_static"
version = "0.2.1"
"libc 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
+[[package]]
+name = "openssl"
+version = "0.7.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "gcc 0.3.26 (registry+https://github.com/rust-lang/crates.io-index)",
+ "lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "openssl-sys 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "openssl-sys-extras 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
[[package]]
name = "openssl-sys"
version = "0.7.8"
"user32-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
+[[package]]
+name = "openssl-sys-extras"
+version = "0.7.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "gcc 0.3.26 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "openssl-sys 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
[[package]]
name = "pkg-config"
version = "0.3.8"
// allow improper ctypes because size_t falls under that in old compilers
#[allow(bad_style, improper_ctypes)]
mod imp {
- use libc;
+ extern crate openssl;
- enum EVP_MD_CTX {}
- enum EVP_MD {}
- enum ENGINE {}
+ use std::io::Write;
+ use self::openssl::crypto::hash::{Hasher, Type};
- extern {
- fn EVP_DigestInit_ex(ctx: *mut EVP_MD_CTX,
- kind: *const EVP_MD,
- imp: *mut ENGINE) -> libc::c_int;
- fn EVP_DigestUpdate(ctx: *mut EVP_MD_CTX,
- d: *const libc::c_void,
- cnt: libc::size_t) -> libc::c_int;
- fn EVP_DigestFinal_ex(ctx: *mut EVP_MD_CTX, md: *mut libc::c_uchar,
- s: *mut libc::c_uint) -> libc::c_int;
- fn EVP_MD_CTX_create() -> *mut EVP_MD_CTX;
- fn EVP_MD_CTX_destroy(ctx: *mut EVP_MD_CTX);
- fn EVP_sha256() -> *const EVP_MD;
- }
-
- pub struct Sha256 { ctx: *mut EVP_MD_CTX }
+ pub struct Sha256(Hasher);
impl Sha256 {
pub fn new() -> Sha256 {
- unsafe {
- let ctx = EVP_MD_CTX_create();
- assert!(!ctx.is_null());
- let ret = Sha256 { ctx: ctx };
- let n = EVP_DigestInit_ex(ret.ctx, EVP_sha256(), 0 as *mut _);
- assert_eq!(n, 1);
- ret
- }
+ Sha256(Hasher::new(Type::SHA256))
}
pub fn update(&mut self, bytes: &[u8]) {
- unsafe {
- let n = EVP_DigestUpdate(self.ctx, bytes.as_ptr() as *const _,
- bytes.len() as libc::size_t);
- assert_eq!(n, 1);
- }
+ let _ = self.0.write_all(bytes);
}
pub fn finish(&mut self) -> [u8; 32] {
- unsafe {
- let mut ret = [0u8; 32];
- let mut out = 0;
- let n = EVP_DigestFinal_ex(self.ctx, ret.as_mut_ptr(), &mut out);
- assert_eq!(n, 1);
- assert_eq!(out, 32);
- ret
- }
- }
- }
-
- impl Drop for Sha256 {
- fn drop(&mut self) {
- unsafe { EVP_MD_CTX_destroy(self.ctx) }
+ let mut ret = [0u8; 32];
+ ret.copy_from_slice(&self.0.finish()[..]);
+ ret
}
}
}